package hash;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) {

        String s = "dgqztusjuu";
        String t = "dqugjzutsu";
        System.out.println(isAnagram(s, t));
        char[] chs = s.toCharArray();
        char[] cht = t.toCharArray();
        Arrays.sort(chs);
        Arrays.sort(cht);
        System.out.println(Arrays.toString(chs));
        System.out.println(Arrays.toString(cht));
    }
    public static boolean isAnagram(String s, String t) {
        if(s==null || t==null || s.length() != t.length()){
            return false;
        }
        int[] arr = new int[26];
        char[] charArr = s.toCharArray();
        System.out.println(Arrays.toString(charArr));
        for(char ch : charArr){
            int i = hashFun(ch);
            arr[i]++;
        }
        System.out.println(Arrays.toString(arr));
        charArr = t.toCharArray();
        for(char ch : charArr){
            int j = hashFun(ch);
            arr[j]--;
        }
        System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] != 0){
                return  false;
            }
        }
        return true;
    }
    public static int hashFun(char ch){
        return ch-'a';

    }

}
